/*
 * @lc app=leetcode.cn id=557 lang=cpp
 *
 * [557] 反转字符串中的单词 III
 */

// @lc code=start
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
    string reverseWords(string s) {
        for(int i = 0; i < s.size(); )
        {
            while(i < s.size() && s[i] == ' ') i++;
            int j = i;
            while(j < s.size() && s[j] != ' ') ++j;
            std::reverse(s.begin() + i, s.begin() + j);
            i = j + 1;
        }
        return s;
    }
};
// @lc code=end

